 

package com.zdkj.subway.stm.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.constant.CommonConstants;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.stm.dto.in.QueryContionDTO;
import com.zdkj.subway.stm.entity.SwStPackageRecordManage;
import com.zdkj.subway.stm.entity.SwStPackageTailboxApply;
import com.zdkj.subway.stm.service.SwStPackageTailboxApplyService;
import com.zdkj.subway.stm.util.BeanUtilsStm;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 库包尾箱申请
 *
 * @author songtuo
 * @date 2020-03-07 14:35:59
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swstpackagetailboxapply" )
@Api(value = "swstpackagetailboxapply", tags = "库包尾箱申请管理")
public class SwStPackageTailboxApplyController {

    private final  SwStPackageTailboxApplyService swStPackageTailboxApplyService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param swStPackageTailboxApply 库包尾箱申请
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getSwStPackageTailboxApplyPage(Page page, SwStPackageTailboxApply swStPackageTailboxApply, QueryContionDTO queryContionDTO) {
        swStPackageTailboxApply.setDelFlag(CommonConstants.STATUS_DEL);
        //按照上交库包时间进行时间筛选
        BeanUtilsStm.addTimeContiontion(swStPackageTailboxApply,queryContionDTO,"APPLY_PACKAGE_TIME");
        return R.ok(swStPackageTailboxApplyService.page(page, Wrappers.query(swStPackageTailboxApply)));
    }


    /**
     * 通过id查询库包尾箱申请
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(swStPackageTailboxApplyService.getById(id));
    }

    /**
     * 新增库包尾箱申请
     * @param swStPackageTailboxApply 库包尾箱申请
     * @return R
     */
    @ApiOperation(value = "新增库包尾箱申请", notes = "新增库包尾箱申请")
    @SysLog("新增库包尾箱申请" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('swstpackagetailboxapply_add')" )
    public R save(@RequestBody SwStPackageTailboxApply swStPackageTailboxApply) {
        SwStPackageTailboxApply defaultObj = ObjectUtils.getDefaultObj(SwStPackageTailboxApply.class);
        BeanUtil.copyProperties(defaultObj, swStPackageTailboxApply, CopyOptions.create().setIgnoreNullValue(true));
        return R.ok(swStPackageTailboxApplyService.save(swStPackageTailboxApply));
    }

    /**
     * 修改库包尾箱申请
     * @param swStPackageTailboxApply 库包尾箱申请
     * @return R
     */
    @ApiOperation(value = "修改库包尾箱申请", notes = "修改库包尾箱申请")
    @SysLog("修改库包尾箱申请" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('swstpackagetailboxapply_edit')" )
    public R updateById(@RequestBody SwStPackageTailboxApply swStPackageTailboxApply) {
        return R.ok(swStPackageTailboxApplyService.updateById(swStPackageTailboxApply));
    }

    /**
     * 通过id删除库包尾箱申请
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除库包尾箱申请", notes = "通过id删除库包尾箱申请")
    @SysLog("通过id删除库包尾箱申请" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('swstpackagetailboxapply_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(swStPackageTailboxApplyService.removeById(id));
    }

    /**
     * @param ids    需要修改的库包ids
     * @param status 需要修改的库包状态
     * @return
     */
    @ApiOperation(value = "修改库包申请状态", notes = "修改库包申请状态")
    @SysLog("修改库包申请状态")
    @PutMapping("/modify/status")
    @PreAuthorize("@pms.hasPermission('swstpackagetailboxapply_update_status')")
    public R updatePackageApplyStatus(@RequestParam(value = "ids") List<Integer> ids, @RequestParam("status") Integer status) {
        return R.ok(swStPackageTailboxApplyService.updatePackageApplyStatus(ids, status));
    }

}
